package chatClientMain;

import java.io.*;

import chat.model.*;
import chatClient.view.*;
import chatClient.controller.*;
/**
* This program initiates other classes that run the communication 
* of a chat client.
* 
* <p>ChatClientMain calls ChatClientGUI to run the user interface; and
* ChatClientConnection to create a new connection.</p>
*<p> 
* At a deep level it implements 'observers' to listen for and respond to new messages, 
* which are called up by ChatClientUI</p>

* @author Tung Nguyen, Trung V Hoang, Rob Bernard, Justin Semmel
* @param serverFile - a list of available servers in a text file.
* @since September 2012
*/
public class ChatClientMain {	
	/*  'chatClientMain.java'  created by: Team N3 for Swinburne Uni HET715s2/Dr. Recep Ulusoy, 2/10/2012 v0.0 (final)
	*   ==============================================================================
	*
	*
	*   It is adapted from an Email Client program assignment developed in an earier subject (HET755) for Lecturer Wei Lai.
	*   
	*
	*       NOTE:   a simple diagnostic log of Server activity is available on the CLI Window display.
	*   
	*   	Java Code Writers:  		Tung Nguyen and Trung Hoang      
	*	Embedded documentation:              Rob Bernard
	*	JavaDoc development:		Justin Semmel
	*
	*
	*  The full program requires the following to be present in a PC to operate:
	*  
	*        - An Ethernet Port, managed by the Windows O/S (or similar);
	*        - a Java Machine (pref. JRE6 or better) with the usual libraries (to run it - see User Manual), and ....
	*        - a User Manual in older 'WORD' format ('J715projectTASK1/TASK2manual.doc').
	*
	*
	*  VERBAL (STEPWISE) FLOWCHART FOR MAIN LOOP:
	*
	*	1.  Setup Client GUI display window 
	*	2.  Setup Server Link                
	*	3.  Add observers to GUI  
	*	4.  Make display visible
	*
	*
	*  CLASSES CALLED:  ChatClientGUI, ChatClientConnection.
	*  ==============    Class and Method summary.  (done by Justin in JavaDocs?)
	*/

	public static void main(String []args)
	{
		// 1.  Setup Client GUI display window
		ChatClientGUI chatClientUI = new ChatClientGUI();
		chatClientUI.init();
		
		//  2.  Setup Server link
		ChatClientConnection clientConnection = new ChatClientConnection();
		clientConnection.ReadServerFile(ApplicationConstant.serverFile);
		clientConnection.createConnection();
		
		//  3.  Add observers
		clientConnection.addObserverChatConnection(chatClientUI);
		chatClientUI.addObserverChatSender(clientConnection);
		clientConnection.addObserverChatListener(chatClientUI);
		
		chatClientUI.setConnection(clientConnection);
		chatClientUI.setVisible(true);
	}
}
